package com.nc.delivery_project.server.util;

import java.sql.SQLException;
import java.util.List;

/**
 * Created by miroshnik on 12/28/2014.
 *
 * CRUD operations contract.
 * See https://en.wikipedia.org/wiki/Create,_read,_update_and_delete
 */
public interface CRUD<T> {

    /**
     * /**
     * Create new entry
     * @param obj - object, which will be saved
     * @return id of inserted object
     * @throws SQLException
     */
    int create(T obj) throws SQLException;

    /**
     * Read all existing entries
     * @return list of all entries
     * @throws SQLException
     */
    List<T> read() throws SQLException;

    /**
     * Read existing entry by id
     * @param id - primary key of entry
     * @return requested object
     * @throws SQLException
     */
    T read(int id) throws SQLException;

    /**
     * Update or edit existing entries
     * @param obj - object with new values
     * @throws SQLException
     */
    void update(T obj) throws SQLException;

    /**
     * Delete existing entries
     * @param id primary key of entry
     * @throws SQLException
     */
    void delete(int id) throws SQLException;
}
